package com.shsnc.agent.util;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

import lombok.extern.slf4j.Slf4j;

/**
 *
 * @author zll
 * @date 2021/8/5
 */
@Slf4j
public class SendUtil {

	private static final String IpAddr="10.142.135.18";
	private static final Integer port=5140;

	public static void send(String req){
		try {
			log.info("发送UDP请求，请求报文{}",req);
			byte[] date = req.getBytes();
			InetAddress inet = InetAddress.getByName(IpAddr);
			DatagramPacket dp = new DatagramPacket(date, date.length, inet,port);
			//创建DatagramSocket对象，数据包的发送和接收对象
			DatagramSocket ds = new DatagramSocket();
			//调用ds对象的方法send，发送数据包
			ds.send(dp);
			ds.close();
		}catch (Exception e){
			log.error("发送UDP请求失败：",e.getMessage());
		}
	}
}
